﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MT.Data;
using MT.MISCommon;

namespace MT.YYGL.CSZhao
{
    public partial class FrmBLB_CX : Form
    {
        private AppEnvir GlobalVar;
        
        public FrmBLB_CX()
        {
            InitializeComponent();
            GlobalVar = MT.MISCommon.MISEnvir.ClientEnvir;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            
            string sSql = "";
            StdCmd cmd = new StdCmd(GlobalVar.ZhangTao.sKJNian);

            sSql = "select * from v_mzsf where  shpbh in (select svalue from yyglsys.sys_parameters where spara='MZGH_BLB')";

            if (comboBox1.SelectedValue.ToString().Trim() != "")
            {
                sSql = "select * from v_mzsf where shpbh='"+comboBox1.SelectedValue.ToString()+"'";
            }
            sSql += " and dzdrq>=" + YYCommon.OraMinDate(this.dtpStart.Value) + " ";
            sSql += " and dzdrq<=" + YYCommon.OraMaxDate(this.dtpEnd.Value) + " ";
           
            //cmd.ExecSelect(sSql);


            DataTable  dtbl = cmd.ExecSelect(sSql).Tables[0];
            dgv.DataSource = dtbl;
            decimal dSL = 0M;
            decimal dJE = 0M;
            for (int i = 0; i < dtbl.Rows.Count; i++)
            {
                dSL = dSL + CommonFunc.cNull(dtbl.Rows[i]["csl"]);
                dJE = dJE + CommonFunc.cNull(dtbl.Rows[i]["cje"]);
            }
            this.txtsl.Text = dSL.ToString();
            this.txtje.Text = dJE.ToString();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (dgv.Rows.Count == 0)
            {
                MessageBox.Show("没有内容不能打印！");
            }
            else
            {
                btnPrint.GridViewSource = dgv;
                btnPrint.PrintObj.Title = lblTitle.Text;
                btnPrint.PrintObj.SetPageHeader("单位:" + GlobalVar.DanWei.DWMC, dtpStart.Value.ToString("yyyy-MM-dd") + "至" + dtpEnd.Value.ToString("yyyy-MM-dd"));
                btnPrint.PrintObj.SetPageFooter("制表: " + GlobalVar.CZY.CZYXM, "", "打印日期：" + DateTime.Today.ToString("yyyy-MM-dd"));
                btnPrint.PrintObj.Preview();
            }
        }

        private void FrmBLB_CX_Load(object sender, EventArgs e)
        {
            dgv.AutoGenerateColumns = false;
            dgv.sy_SetReadOnlyColor();

            StdCmd cmd = new StdCmd(GlobalVar.ZhangTao.sKJNian);
            string sql = "select * from sv_goods where sghbj='*'";
            DataTable dt = cmd.ExecSelect(sql).Tables[0];
            if (dt != null)
            {
                //绑定
                comboBox1.DataSource = dt;
                comboBox1.DisplayMember = "shpmc";
                comboBox1.ValueMember = "shpbh";
                DataRow dr = dt.NewRow();
                dt.Rows.InsertAt(dr, 0);
                comboBox1.SelectedIndex = 0;
            }
        }
    }
}